﻿using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using System.Runtime.InteropServices;

namespace SUNRPA.CONTROLS.IMPL.util {
    public abstract class BrowserUtil {
        public const string GOOGLE_EXE = "chrome.exe";
        public const string IE_EXE = "iexplore.exe";
        public const string EDGE_EXE = "msedge.exe";
        public const string GOOGLE_PNAME = "Google Chrome";
        public const string EDGE_PNAME = "Microsoft Edge";
        public const string IE_PNAME = "Internet Explorer";

        public abstract object OpenUrl(string url, int expireTime, [Optional]string appPath);

        public static BrowserType JudgeBrowserByWindowClass(string text) {
            if(text.Contains(DefaultContents.GOOGLE_WIN_CLASS) || text.Contains(DefaultContents.GOOGLE_WIN_CLASS1)) {
                return BrowserType.GOOGLE;
            } else { 
                return BrowserType.NAB;
            }      
        }

        public abstract void DealDownLoadDialog(bool isDownload, string parentPath, string fileName, int expireTime);
        public abstract bool IsDownloadExpire(int downloadId, int expireTime); 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="waitType">0等待出现，1等待消失</param>
        /// <param name="canExpire"></param>
        /// <param name="ele"></param>
        /// <param name="webPage"></param>
        /// <param name="expireTime"></param>
        /// <returns>true等待成功，否则等待失败</returns>
        public abstract bool WaitWebEle(int waitType, bool canExpire, WebElement ele, object webPage, [Optional]int expireTime);

        public abstract void ActiveBrowser();

        public abstract object SearchLatestDownloadTask();
    }
}
